package logic

import (
	"context"
	"github.com/google/uuid"
	"money/pkg"
	"strconv"
	"vip_srv/vip"

	"money/internal/svc"
	"money/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type MemberLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

var Num int = 5

func NewMemberLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MemberLogic {
	return &MemberLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *MemberLogic) Member(req *types.MemberRequest) (resp *types.MemberReesponse, err error) {
	// todo: add your logic here and delete this line

	viper, err := l.svcCtx.VipSrv.FindOneInfoByViper(l.ctx, &vip.FindOneInfoByViperRequest{Id: int64(req.Id)})
	if err != nil {
		return &types.MemberReesponse{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}

	if viper.Cover == 1 { //封禁
		return &types.MemberReesponse{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	if viper.Cover == 2 { //冻结
		return &types.MemberReesponse{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}

	sum := int(viper.Price) * Num

	pkg.Alipay(uuid.NewString(), strconv.Itoa(sum))

	return &types.MemberReesponse{
		Code:    200,
		Message: "下单成功",
		Data:    nil,
		Status:  int(viper.Status),
		ShopNum: viper.ShopNum,
	}, nil
}
